/* 
* Copyright (C) 2011-2018 ShenZhen iBOXSaaS Information Technology Co.,Ltd. 
* 
* All right reserved. 
* 
* This software is the confidential and proprietary 
* information of iBOXSaaS Company of China. 
* ("Confidential Information"). You shall not disclose 
* such Confidential Information and shall use it only 
* in accordance with the terms of the contract agreement 
* you entered into with iBOXSaaS inc. 
* 
*/

package org.iboxpay.open.common.utils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.iboxpay.open.common.constants.LogEnums;

import com.iboxpay.common.utils.TimeUtils;

/**
 * 
 * AccessLogUtils.java
 * 
 * @author xuxiao
 * @date 2018/06/15
 */
public class AccessLogUtils {
    
    /**
     * 获取访问日志
     * @param startTime
     * @param endTime
     * @param serviceId
     * @param transactionId
     * @param result
     * @return
     */
    public static Map<String, String> getAccessMap(long startTime, long endTime, String serviceId, String transactionId, String moduleName, Object result, HttpServletRequest request) {
        Map<String, String> accessMap = new HashMap<>();
        startTime = startTime == 0 ? System.currentTimeMillis() : startTime;
        endTime = endTime == 0 ? System.currentTimeMillis() : endTime;
        accessMap.put(LogEnums.module.getCode(), moduleName);
        accessMap.put(LogEnums.serviceId.getCode(), serviceId);
        accessMap.put(LogEnums.startTime.getCode(), TimeUtils.toStringFormat_1(new Date(startTime)));
        accessMap.put(LogEnums.endTime.getCode(), TimeUtils.toStringFormat_1(new Date(endTime)));
        accessMap.put(LogEnums.timeDiff.getCode(), String.valueOf(endTime - startTime));
        accessMap.put(LogEnums.transactionId.getCode(), transactionId);
        LogUtils.fillIp(accessMap, request, transactionId);
        LogUtils.fillResult(accessMap, result);
        return accessMap;
    }

}
